package com.cxyxj.conditional;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author: gongj
 * @create: 2022-01-27 16:06
 */
public class ProductCondition implements Condition {

    /**
     *
     * @param context：可以获得Bean工厂、Environment、bean定义注册器、ClassLoader、ResourceLoader
     * @param metadata：可以获得注解信息，比如：方法名称、
     * @return
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        String property = environment.getProperty("enable.flag");
        //如果 enable.flag 的值为 false 或者为空
        if(!Boolean.parseBoolean(property)){
            return true;
        }
        return false;
    }

}
